﻿using System;
using System.Collections.Generic;
using System.Text;
using Antu.WebControls;
using System.Web.UI.WebControls;
using System.Web;
using EluZSProvider;
using Antu.Core.Services;
using System.Data;

namespace WebSys.UI.OfficeFlow
{
    public class fwbuchangjuedingControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        MPPersistence Persistence1; Panel panel1;
        TextBox txt字, txt第, txt号, txt区, txt公司, txt门牌号, 门牌号1, 门牌号2, txt被征收人, 字1, 第1, 号2, 号3, 号5, 区1, 区2, 区3, 区4, 区5, 区6, 公司1, 被征收人1, 被征收人2, 被征收人3, 被征收人4;

        TextBox 公司2;
        TextBox txt代表人;
        TextBox txt征收人;
        TextBox txt丘号;
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            NameInfo();
            panel1 = (Panel)FindControl("panel1");
            Persistence1 = (MPPersistence)FindControl("Persistence1");
            if (!base.Page.IsPostBack)
            {

                Persistence1.Table = "zs_征收补偿决定书";//数据库中对应的表
                Persistence1.Key = "IID";//表的主键列名称
                Persistence1.KeyValue = HttpContext.Current.Request.QueryString["IID"];//主键列的值
                Persistence1.ConnStr = _EluZSDataProvider.GetConnectionString();//数据库连接字符串
            }
            Persistence1.BindControl = panel1;//持久化控件的控制对象为Panel中的所以的字段，panel1是Panel的ID
            Button Button1 = (Button)FindControl("Button1");
            if (string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["IID"]))
            {
                Button1.Visible = false;

            }
            else
            {
                Button1.Click += new EventHandler(Button1_Click);
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Persistence1.Update();
            base.Page.Response.Redirect("fwbuchangjueding.aspx?IID=" + base.Page.Request["IID"]);
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            TextBox txtIID = (TextBox)FindControl("txtIID");
            txtIID.Text = HttpContext.Current.Request.QueryString["IID"];
            字1.Text = txt字.Text.Trim();
            第1.Text = txt第.Text.Trim();
            号2.Text = txt号.Text.Trim();
            号3.Text = txt号.Text.Trim();
            号5.Text = txt号.Text.Trim();
            区1.Text = txt区.Text.Trim();
            区2.Text = txt区.Text.Trim();
            区3.Text = txt区.Text.Trim();
            区4.Text = txt区.Text.Trim();
            区5.Text = txt区.Text.Trim();
            区6.Text = txt区.Text.Trim();
            公司1.Text = txt公司.Text.Trim();
            公司2.Text = txt公司.Text.Trim();
            被征收人1.Text = txt被征收人.Text.Trim();
            被征收人2.Text = txt被征收人.Text.Trim();
            被征收人3.Text = txt被征收人.Text.Trim();
            被征收人4.Text = txt被征收人.Text.Trim();
            门牌号1.Text = txt门牌号.Text.Trim();
            门牌号2.Text = txt门牌号.Text.Trim();

            string sql = @"select * from zs_project where id=(
select pid from zs_prono where id =(select PID from zs_zzbcjfenhu where id= 
 (select 关联ID from xt_instance_ext  where iid='" + txtIID.Text + "')" + @"
))";
            DataTable dt = _EluZSDataProvider.GetOneDs("(" + sql + ")", "*", "").Tables[0];
            if (dt.Rows.Count > 0)
            {
                txt代表人.Text = dt.Rows[0]["法定代表人"].ToString();
                txt公司.Text=dt.Rows[0]["评估机构"].ToString();
                公司1.Text = dt.Rows[0]["评估机构"].ToString();
                公司2.Text = dt.Rows[0]["评估机构"].ToString();
                txt征收人.Text = dt.Rows[0]["征收部门"].ToString();
            }

            string sql2 = @"select * from zs_zsperson where id =
(select zspid from zs_zzbcjfenhu where id=(
select 关联ID from xt_instance_ext  where iid='" + txtIID.Text + "' ))";
            DataTable dt2 = _EluZSDataProvider.GetOneDs("(" + sql2 + ")", "*", "").Tables[0];
            if (dt2.Rows.Count > 0)
            {
                txt丘号.Text = dt2.Rows[0]["丘权号"].ToString();
            }
        }

        protected void NameInfo()
        {
            txt字 = (TextBox)FindControl("txt字");
            txt第 = (TextBox)FindControl("txt第");
            txt号 = (TextBox)FindControl("txt号");
            txt区 = (TextBox)FindControl("txt区");
            txt公司 = (TextBox)FindControl("txt公司");
            txt门牌号 = (TextBox)FindControl("txt门牌号");
            txt被征收人 = (TextBox)FindControl("txt被征收人");
            字1 = (TextBox)FindControl("字1");
            第1 = (TextBox)FindControl("第1");
            号2 = (TextBox)FindControl("号2");
            号3 = (TextBox)FindControl("号3");
            号5 = (TextBox)FindControl("号5");
            区1 = (TextBox)FindControl("区1");
            区2 = (TextBox)FindControl("区2");
            区3 = (TextBox)FindControl("区3");
            区4 = (TextBox)FindControl("区4");
            区5 = (TextBox)FindControl("区5");
            区6 = (TextBox)FindControl("区6");
            公司1 = (TextBox)FindControl("公司1");
            被征收人1 = (TextBox)FindControl("被征收人1");
            被征收人2 = (TextBox)FindControl("被征收人2");
            被征收人3 = (TextBox)FindControl("被征收人3");
            被征收人4 = (TextBox)FindControl("被征收人4");
            门牌号1 = (TextBox)FindControl("门牌号1");
            门牌号2 = (TextBox)FindControl("门牌号2");

            txt代表人 = (TextBox)FindControl("txt代表人");
            公司1 = (TextBox)FindControl("公司1");
            公司2 = (TextBox)FindControl("公司2");

            txt征收人 = (TextBox)FindControl("txt征收人");
            txt丘号 = (TextBox)FindControl("txt丘号");
        }
    }
}